from utils.time_util import today_zero_stamp, stamp_ms

SYMBOL = 0  ##货币
PERIOD = 0  ##周期
MODE = 0  ##策略模式

# 集金网交易策略
TRADE_CELVE = ""


def getUrl(startTime):
    '''
    拼接完整的url
    '''
    global SYMBOL, PERIOD, MODE
    if SYMBOL == 0 or PERIOD == 0 or MODE == 0:
        print("参数信息为空")
        return ""
    if startTime == "":
        startTime = str(stamp_ms(today_zero_stamp()))

    beginTime = "beginTime=" + startTime + "&"
    endTime = "endTime=" + str(stamp_ms()) + "&"
    URL = "https://indicator2.jijinhao.net/query/period?symbol=" + str(SYMBOL) + "&period=m" + str(
        PERIOD) + "&" + beginTime + endTime
    if MODE == 1:
        URL = URL + "params={\"buyStep\":20,\"sellStep\":10,\"account\":{\"balance\":100000,\"risk\":0.01}}&name=turtles"
    else:
        URL = URL + "params={\"e\":2}&name=jjx"
    return URL


def setParams(symbol, period, mode):
    global SYMBOL, PERIOD, MODE
    SYMBOL = symbol
    PERIOD = period
    MODE = mode


def getJiJin():
    global TRADE_CELVE
    return TRADE_CELVE


def setJiJin(value):
    global TRADE_CELVE
    if value != "" and value[-1] == "_":
        TRADE_CELVE = value[0:-1]
    else:
        TRADE_CELVE = value
